/**
 *  同步与异步
 *  阻塞与非阻塞
 *  异步 IO
 *  事件循环与事件驱动
 *  单线程
 *  进程
 *  子进程
 *  进程通讯
 * */

const _promise = new Promise(function(resolve, reject) {
    setTimeout(function() {
        resolve('foo');
    }, 300);
});
_promise.then(function(value) {
    console.log(value);
    // expected output: "foo"
});
const doSync = (sth, time) =>  new Promise(resolve => {
      setTimeout(() => {
          console.log(sth + '用了' + time + '毫秒');
          resolve()
      }, time)
  });

const doAsync = (sth, time, cb) => {
        setTimeout(() => {
            console.log(sth + '用了' + time + '毫秒');
            cb&&cb()
        }, time)
};

const doElse = (sth) => {
  console.log(sth)
};

const Scott = {doSync, doAsync};
const Meizi = {doSync, doAsync, doElse};

(async ()=> {
    console.log('case 1: 来到门口');
    await Scott.doSync('刷牙', 1000);
    console.log('case 2: 一直等待');
    await Meizi.doSync('刷牙', 2000);
})();